package cn.songhaiqing.walle.help;

import android.content.Context;
import android.util.Log;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import cn.songhaiqing.walle.bean.DayTime;
import cn.songhaiqing.walle.bean.FirstSyncBean;
import cn.songhaiqing.walle.bean.HistoryHour;
import cn.songhaiqing.walle.bean.ImgVersion;
import cn.songhaiqing.walle.bean.NewSleepHis;
import cn.songhaiqing.walle.bean.NewSleepRealData;
import cn.songhaiqing.walle.global.Global;

public class SleepHelper {
    public static final String KEY_DAYTIME_HOUR_BEGIN = "KEY_DAYTIME_HOUR_BEGIN";
    public static final String KEY_DAYTIME_HOUR_END = "KEY_DAYTIME_HOUR_END";
    public static final String KEY_DAYTIME_LAST_DATE = "KEY_DAYTIME_LAST_DATE";
    public static final String KEY_DAYTIME_MINUTE_BEGIN = "KEY_DAYTIME_MINUTE_BEGIN";
    public static final String KEY_DAYTIME_MINUTE_END = "KEY_DAYTIME_MINUTE_END";
    public static final int NEW_SLEEP_DEEP = 128;
    public static final int NEW_SLEEP_LIGHT = 168;
    public static final int NEW_SLEEP_WEAR = 128;

    public static NewSleepRealData getRealNewSleepTime(Context context, Map<Calendar, HistoryHour> map, List<HistoryHour> list, Calendar currentDate) {
        String[] sleeps;
        int ii;
        List<HistoryHour> newSleepHises = new ArrayList<>();
        boolean isBegin = false;
        boolean isFirst = false;
        boolean isEnd = false;
        int begin_position = 0;
        int end_position = 0;
        int day = currentDate.get(5);
        int sleep_max = -1;
        int sleep_min =0;// ActivityChooserView.ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
        int startSleepPosition = -1;
        int startSleepMark = 0;
        int endSleepPosition = -1;
        int endSleepMark = 0;
        if (!(list == null || map == null)) {
            int i = 0;
            while (true) {
                if (i >= list.size()) {
                    break;
                }
                HistoryHour sleepHis = list.get(i);
                Calendar sleepHis_datetime = sleepHis.getDate();
                String[] sleep = sleepHis.getSleeps();
                int hisDay = sleepHis.getDate().get(5);
                int hisHour = sleepHis.getDate().get(11);
                if ((hisDay < day || hisHour <= 8) && !isBegin && map.containsKey(sleepHis_datetime) && sleep != null && sleep != null) {
                    int ii2 = 0;
                    while (true) {
                        if (ii2 >= sleep.length) {
                            break;
                        }
                        int sleep_value = Integer.parseInt(sleep[ii2]);
                        if (sleep_value <= 168 && sleep_value >= 128) {
                            if (startSleepMark == 0) {
                                startSleepPosition = i;
                                begin_position = ii2;
                            }
                            startSleepMark++;
                            if (startSleepMark == 4) {
                                isBegin = true;
                                isFirst = true;
                                break;
                            }
                        } else {
                            startSleepMark = 0;
                            startSleepPosition = -1;
                        }
                        ii2++;
                    }
                }
                if (isBegin) {
                    if (isFirst) {
                        if (startSleepPosition != -1) {
                            if (startSleepPosition != i) {
                                HistoryHour his = list.get(startSleepPosition);
                                his.setMinute_dif(getMinute_dif_newSleep(his.getDate()));
                                newSleepHises.add(his);
                                newSleepHises.add(sleepHis);
                            } else {
                                sleepHis.setMinute_dif(getMinute_dif_newSleep(sleepHis_datetime));
                                newSleepHises.add(sleepHis);
                            }
                        }
                        isFirst = false;
                    } else {
                        newSleepHises.add(sleepHis);
                    }
                }
                if (sleepHis_datetime.get(11) >= 6 && currentDate.get(5) == sleepHis_datetime.get(5) && (map.containsKey(sleepHis_datetime) && isBegin)) {
                    if (sleepHis.equals(list.get(startSleepPosition))) {
                        ii = begin_position;
                    } else {
                        ii = 0;
                    }
                    if (sleep == null) {
                        return null;
                    }
                    while (true) {
                        if (ii >= sleep.length) {
                            break;
                        }
                        int sleep_value2 = Integer.parseInt(sleep[ii]);
                        if (sleep_value2 < 128) {
                            endSleepPosition = i;
                            end_position = ii;
                            isEnd = true;
                            break;
                        }
                        if (sleep_value2 > 168) {
                            if (endSleepMark == 0) {
                                endSleepPosition = i;
                                end_position = ii;
                            }
                            endSleepMark++;
                            if (endSleepMark == 4) {
                                isEnd = true;
                                break;
                            }
                        } else {
                            endSleepMark = 0;
                            endSleepPosition = -1;
                        }
                        ii++;
                    }
                }
                if (!isEnd) {
                    i++;
                } else if (endSleepPosition != -1) {
                    if (endSleepPosition != i) {
                        HistoryHour his2 = list.get(endSleepPosition);
                        his2.setMinute_dif(getMinute_dif_newSleep(his2.getDate()));
                        newSleepHises.remove(sleepHis);
                    } else {
                        sleepHis.setMinute_dif(getMinute_dif_newSleep(sleepHis_datetime));
                    }
                }
            }
            if (isBegin && !isEnd) {
                FirstSyncBean firstSyncBean =null;// DatabaseProvider.getInstance(context).querySyncTime(FormatHelper.sdf_yyyyMMdd.format(currentDate.getTime()));
                if (firstSyncBean == null) {
                    return null;
                }
                try {
                    Calendar firstCal = Calendar.getInstance();
                    firstCal.setTime(FormatHelper.sdf_yyyyMMddHHmm.parse(firstSyncBean.toString()));
                    int dif = Integer.parseInt(firstSyncBean.getHour_minute().substring(2, 4));
                    int count = dif / 5;
                    int over = dif % 5;
                    if (dif > 57) {
                        firstCal.set(11, firstCal.get(11) + 1);
                        end_position = 0;
                    } else if (over < 3) {
                        end_position = count;
                    } else {
                        end_position = count + 1;
                    }
                    Iterator<HistoryHour> iterator = newSleepHises.iterator();
                    while (iterator.hasNext()) {
                        if (iterator.next().getDate().after(firstCal)) {
                            iterator.remove();
                        }
                    }
                    if (newSleepHises.size() > 0) {
                        if (over < 3) {
                            newSleepHises.get(newSleepHises.size() - 1).setMinute_dif(over);
                        } else {
                            newSleepHises.get(newSleepHises.size() - 1).setMinute_dif(over - 5);
                        }
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            if (!isBegin) {
                for (int j = 0; j < list.size(); j++) {
                    HistoryHour hour = list.get(j);
                    int step = hour.getStep();
                    int hisDay2 = hour.getDate().get(5);
                    int hisHour2 = hour.getDate().get(11);
                    Calendar sleepHis_datetime2 = hour.getDate();
                    if ((hisDay2 != day || hisHour2 <= 8) && !isBegin && map.containsKey(sleepHis_datetime2) && step < 30 && j < list.size() - 1) {
                        if (list.get(j + 1).getStep() <= 100) {
                            String[] sleeps2 = hour.getSleeps();
                            if (sleeps2 != null) {
                                int min =0;// ActivityChooserView.ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
                                for (int ii3 = 0; ii3 < sleeps2.length; ii3++) {
                                    int sleep_value3 = Integer.parseInt(sleeps2[ii3]);
                                    if (sleep_value3 < 128) {
                                        isBegin = false;
                                        hour.setMinute_dif(0);
                                    //    min = ActivityChooserView.ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
                                        begin_position = 0;
                                    } else if (sleep_value3 < min && sleep_value3 >= 128) {
                                        hour.setMinute_dif(getMinute_dif_newSleep(sleepHis_datetime2));
                                        min = sleep_value3;
                                        begin_position = ii3;
                                        isBegin = true;
                                    }
                                }
                            }
                        } else {
                            continue;
                        }
                    }
                    if (isBegin) {
                        newSleepHises.add(hour);
                    }
                    if (hisHour2 >= 6 && hisDay2 == day && map.containsKey(sleepHis_datetime2) && isBegin && (sleeps = hour.getSleeps()) != null) {
                        if (step >= 30) {
                           // int min2 = ActivityChooserView.ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
                            for (int ii4 = 0; ii4 < sleeps.length; ii4++) {
                                int sleep_value4 = Integer.parseInt(sleeps[ii4]);

                            }
                        } else {
                            int ii5 = 0;
                            while (true) {
                                if (ii5 >= sleeps.length) {
                                    break;
                                } else if (Integer.parseInt(sleeps[ii5]) < 128) {
                                    end_position = ii5;
                                    hour.setMinute_dif(getMinute_dif_newSleep(sleepHis_datetime2));
                                    isEnd = true;
                                    break;
                                } else {
                                    ii5++;
                                }
                            }
                        }
                    }
                    if (isEnd) {
                        break;
                    }
                }
                if (isBegin && !isEnd) {
                    FirstSyncBean firstSyncBean2 = null;//DatabaseProvider.getInstance(context).querySyncTime(FormatHelper.sdf_yyyyMMdd.format(currentDate.getTime()));
                    if (firstSyncBean2 == null) {
                        return null;
                    }
                    try {
                        Calendar firstCal2 = Calendar.getInstance();
                        firstCal2.setTime(FormatHelper.sdf_yyyyMMddHHmm.parse(firstSyncBean2.toString()));
                        int dif2 = Integer.parseInt(firstSyncBean2.getHour_minute().substring(2, 4));
                        int count2 = dif2 / 5;
                        int over2 = dif2 % 5;
                        if (dif2 > 57) {
                            firstCal2.set(11, firstCal2.get(11) + 1);
                            end_position = 0;
                        } else if (over2 < 3) {
                            end_position = count2;
                        } else {
                            end_position = count2 + 1;
                        }
                        Iterator<HistoryHour> iterator2 = newSleepHises.iterator();
                        while (iterator2.hasNext()) {
                            if (iterator2.next().getDate().after(firstCal2)) {
                                iterator2.remove();
                            }
                        }
                        if (newSleepHises.size() > 0) {
                            if (over2 < 3) {
                                newSleepHises.get(newSleepHises.size() - 1).setMinute_dif(over2);
                            } else {
                                newSleepHises.get(newSleepHises.size() - 1).setMinute_dif(over2 - 5);
                            }
                        }
                    } catch (ParseException e2) {
                        e2.printStackTrace();
                    }
                }
                for (int i2 = 0; i2 < newSleepHises.size(); i2++) {
                    String[] sleeps3 = newSleepHises.get(i2).getSleeps();
                    if (sleeps3 != null) {
                        if (i2 == 0) {
                            for (int start_i = begin_position; start_i < sleeps3.length; start_i++) {
                                int sleep2 = Integer.parseInt(sleeps3[start_i]);
                                if (sleep_max < sleep2 && sleep2 >= 128) {
                                    sleep_max = sleep2;
                                }
                                if (sleep_min > sleep2 && sleep2 >= 128) {
                                    sleep_min = sleep2;
                                }
                            }
                        } else if (i2 == newSleepHises.size() - 1) {
                            for (int end_i = 0; end_i <= end_position; end_i++) {
                                int sleep3 = Integer.parseInt(sleeps3[end_i]);
                                if (sleep_max < sleep3 && sleep3 >= 128) {
                                    sleep_max = sleep3;
                                }
                                if (sleep_min > sleep3 && sleep3 >= 128) {
                                    sleep_min = sleep3;
                                }
                            }
                        } else {
                            for (String str : sleeps3) {
                                int sleep4 = Integer.parseInt(str);
                                if (sleep_max < sleep4 && sleep4 >= 128) {
                                    sleep_max = sleep4;
                                }
                                if (sleep_min > sleep4 && sleep4 >= 128) {
                                    sleep_min = sleep4;
                                }
                            }
                        }
                    }
                }
            }
        }
        NewSleepRealData sleepRealData = new NewSleepRealData();
        sleepRealData.setBegin_position(begin_position);
        sleepRealData.setEnd_position(end_position);
        sleepRealData.setNewSleepHises1(newSleepHises);
        sleepRealData.setSleep_max(sleep_max);
        sleepRealData.setSleep_min(sleep_min);
        return sleepRealData;
    }

    public static DayTime getDayTime(Context context, int profileID, Calendar current) {
        DayTime dayTime = new DayTime();
        int hourBegin = 0;
        int hourEnd = 24;
        int minuteBegin = 0;
        int minuteEnd = 0;
        DayTime dayTimeTemp = null;//DatabaseProvider.getInstance(context).queryDayTime(context, profileID, current);
        if (dayTimeTemp != null) {
            hourBegin = dayTimeTemp.getHourBegin();
            hourEnd = dayTimeTemp.getHourEnd();
            minuteBegin = dayTimeTemp.getMinuteBegin();
            minuteEnd = dayTimeTemp.getMinuteEnd();
        } else {
            int defaultDevice = DeviceHelper.getDefaultDevice();
            long lastDate = SpHelper.getLong(KEY_DAYTIME_LAST_DATE + DeviceHelper.ARRAY_DEVICE[defaultDevice], -1);
            if (lastDate != -1) {
                Calendar calLast = Calendar.getInstance();
                calLast.setTimeInMillis(lastDate);
                if (!current.before(calLast)) {
                    hourBegin = SpHelper.getInt(KEY_DAYTIME_HOUR_BEGIN + DeviceHelper.ARRAY_DEVICE[defaultDevice], 0);
                    hourEnd = SpHelper.getInt(KEY_DAYTIME_HOUR_END + DeviceHelper.ARRAY_DEVICE[defaultDevice], 24);
                    minuteBegin = SpHelper.getInt(KEY_DAYTIME_MINUTE_BEGIN + DeviceHelper.ARRAY_DEVICE[defaultDevice], 0);
                    minuteEnd = SpHelper.getInt(KEY_DAYTIME_MINUTE_END + DeviceHelper.ARRAY_DEVICE[defaultDevice], 0);
                }
            }
            DayTime dayTimeDatabase = new DayTime();
            dayTimeDatabase.setDate(current);
            dayTimeDatabase.setHourBegin(hourBegin);
            dayTimeDatabase.setHourEnd(hourEnd);
            dayTimeDatabase.setMinuteBegin(minuteBegin);
            dayTimeDatabase.setMinuteEnd(minuteEnd);
            //DatabaseProvider.getInstance(context).insertDayTime(context, profileID, dayTimeDatabase);
        }
        dayTime.setHourBegin(hourBegin);
        dayTime.setHourEnd(hourEnd);
        dayTime.setMinuteBegin(minuteBegin);
        dayTime.setMinuteEnd(minuteEnd);
        Log.i("changeSync", "hourBegin:" + hourBegin + "\thourEnd:" + hourEnd + "\tminuteBegin:" + minuteBegin + "\tminuteEnd:" + minuteEnd);
        return dayTime;
    }

    public static DayTime getLastDayTime() {
        DayTime dayTime = new DayTime();
        int defaultDevice = DeviceHelper.getDefaultDevice();
        Calendar cal_last = Calendar.getInstance();
        cal_last.setTimeInMillis(SpHelper.getLong(KEY_DAYTIME_LAST_DATE + DeviceHelper.ARRAY_DEVICE[defaultDevice], -1));
        dayTime.setDate(cal_last);
        dayTime.setHourBegin(SpHelper.getInt(KEY_DAYTIME_HOUR_BEGIN + DeviceHelper.ARRAY_DEVICE[defaultDevice], 0));
        dayTime.setHourEnd(SpHelper.getInt(KEY_DAYTIME_HOUR_END + DeviceHelper.ARRAY_DEVICE[defaultDevice], 24));
        dayTime.setMinuteBegin(SpHelper.getInt(KEY_DAYTIME_MINUTE_BEGIN + DeviceHelper.ARRAY_DEVICE[defaultDevice], 0));
        dayTime.setMinuteEnd(SpHelper.getInt(KEY_DAYTIME_MINUTE_END + DeviceHelper.ARRAY_DEVICE[defaultDevice], 0));
        return dayTime;
    }

    public static void setLastDayTime(DayTime dayTime) {
        if (dayTime != null) {
            int defaultDevice = DeviceHelper.getDefaultDevice();
            SpHelper.putLong(KEY_DAYTIME_LAST_DATE + DeviceHelper.ARRAY_DEVICE[defaultDevice], dayTime.getDate().getTimeInMillis());
            SpHelper.putInt(KEY_DAYTIME_HOUR_BEGIN + DeviceHelper.ARRAY_DEVICE[defaultDevice], dayTime.getHourBegin());
            SpHelper.putInt(KEY_DAYTIME_HOUR_END + DeviceHelper.ARRAY_DEVICE[defaultDevice], dayTime.getHourEnd());
            SpHelper.putInt(KEY_DAYTIME_MINUTE_BEGIN + DeviceHelper.ARRAY_DEVICE[defaultDevice], dayTime.getMinuteBegin());
            SpHelper.putInt(KEY_DAYTIME_MINUTE_END + DeviceHelper.ARRAY_DEVICE[defaultDevice], dayTime.getMinuteBegin());
        }
    }

    public static void setLastDayTime(DayTime dayTime, int type) {
        if (dayTime != null) {
            SpHelper.putLong(KEY_DAYTIME_LAST_DATE + DeviceHelper.ARRAY_DEVICE[type], dayTime.getDate().getTimeInMillis());
            SpHelper.putInt(KEY_DAYTIME_HOUR_BEGIN + DeviceHelper.ARRAY_DEVICE[type], dayTime.getHourBegin());
            SpHelper.putInt(KEY_DAYTIME_HOUR_END + DeviceHelper.ARRAY_DEVICE[type], dayTime.getHourEnd());
            SpHelper.putInt(KEY_DAYTIME_MINUTE_BEGIN + DeviceHelper.ARRAY_DEVICE[type], dayTime.getMinuteBegin());
            SpHelper.putInt(KEY_DAYTIME_MINUTE_END + DeviceHelper.ARRAY_DEVICE[type], dayTime.getMinuteBegin());
        }
    }

    public static List<HistoryHour> getRealSleepTime(Context context, Map<Calendar, HistoryHour> map, List<HistoryHour> list, Calendar currentDate) {
        List<HistoryHour> historyHourList = new ArrayList<>();
        Calendar calendar_End = null;
        boolean isBegin = false;
        boolean isUnWear = true;
        int begin_position = 0;
        int day = currentDate.get(5);
        if (!(list == null || map == null)) {
            Iterator<HistoryHour> it = list.iterator();
            loop0:
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                HistoryHour history_hour = it.next();
                Calendar history_datetime = history_hour.getDate();
                int step = history_hour.getStep();
                int[] sleep16 = null;//CalculateHelper.calculateSleepGrade(history_hour.getSleepGrade());
                if (isBegin || step != 0 || sleep16[0] != 10 || sleep16[1] != 10 || sleep16[2] != 10 || sleep16[3] != 10) {
                    int hisDay = history_hour.getDate().get(5);
                    int hisHour = history_hour.getDate().get(11);
                    if ((hisDay < day || hisHour <= 8) && !isBegin && map.containsKey(history_datetime) && step < 50) {
                        int ii = sleep16.length - 1;
                        while (true) {
                            if (ii < 0) {
                                break;
                            } else if (sleep16[ii] == 10) {
                                history_hour.setMinute_dif(getMinute_dif(history_datetime));
                                isBegin = true;
                                begin_position = ii;
                                break;
                            } else {
                                ii--;
                            }
                        }
                    }
                    if (isBegin) {
                        historyHourList.add(history_hour);
                    }
                    if (history_datetime.get(11) >= 6 && currentDate.get(5) == history_datetime.get(5) && map.containsKey(history_datetime)) {
                        if ((step > 50) && isBegin) {
                            int dif_minute = 0;
                            for (int ii2 = sleep16.length - 1; ii2 >= 0; ii2--) {
                                if (sleep16[ii2] != 10) {
                                    calendar_End = history_datetime;
                                    history_hour.setMinute_dif(dif_minute + getMinute_dif(history_datetime));
                                    int end_position = 3 - ii2;
                                    break loop0;
                                }
                                dif_minute += 15;
                            }
                            continue;
                        } else {
                            continue;
                        }
                    }
                }
            }
            if (calendar_End == null) {
                FirstSyncBean firstSyncBean =null;// DatabaseProvider.getInstance(context).querySyncTime(FormatHelper.sdf_yyyyMMdd.format(currentDate.getTime()));
                if (firstSyncBean == null) {
                    return null;
                }
                int dif = 0;
                try {
                    Calendar firstCal = Calendar.getInstance();
                    firstCal.setTime(FormatHelper.sdf_yyyyMMddHHmm.parse(firstSyncBean.toString()));
                    calendar_End = firstCal;
                    dif = Integer.parseInt(firstSyncBean.getHour_minute().substring(2, 4));
                    if (dif > 52) {
                        firstCal.set(11, firstCal.get(11) + 1);
                    } else {
                        int count = dif / 15;
                        int over = dif % 15;
                        if (dif >= 8) {
                            if (dif < 8 || over <= 0) {
                                int end_position2 = 3 - count;
                            } else if (over > 7) {
                                int end_position3 = (3 - count) + 1;
                            } else {
                                int end_position4 = 3 - count;
                            }
                        }
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                if (calendar_End != null) {
                    Iterator<HistoryHour> iterator = historyHourList.iterator();
                    while (iterator.hasNext()) {
                        if (iterator.next().getDate().after(calendar_End)) {
                            iterator.remove();
                        }
                    }
                    if (historyHourList.size() > 0) {
                        if (dif > 52) {
                            historyHourList.get(historyHourList.size() - 1).setMinute_dif(dif - 60);
                        } else {
                            historyHourList.get(historyHourList.size() - 1).setMinute_dif(dif);
                        }
                    }
                }
            }
            for (int i = 0; i < historyHourList.size(); i++) {
                int[] sleep162 =null;// CalculateHelper.calculateSleepGrade(historyHourList.get(i).getSleepGrade());
                for (int ii3 = 0; ii3 < sleep162.length; ii3++) {
                    if (i < historyHourList.size() - 1 && sleep162[ii3] < 10) {
                        isUnWear = false;
                    }
                    if (i == 0 && ii3 <= begin_position && sleep162[ii3] == 15) {
                        return null;
                    }
                }
            }
            if (isUnWear) {
                return null;
            }
        }
        int deepSleep = 0;
        if (historyHourList != null && historyHourList.size() > 0) {
            HistoryHour fir_his = historyHourList.get(0);
            if (fir_his != null) {
                int sleepMove = fir_his.getSleepGrade();
                int agreement = fir_his.getAgreement();

            }
            for (int i2 = 1; i2 < historyHourList.size() - 1; i2++) {
                HistoryHour historyHour = historyHourList.get(i2);
                if (historyHour != null) {
                    int sleepMove2 = historyHour.getSleepGrade();
                    int agreement2 = historyHour.getAgreement();

                }
            }
            HistoryHour las_his = historyHourList.get(historyHourList.size() - 1);
            if (las_his != null) {
                int sleepMove3 = las_his.getSleepGrade();
                int agreement3 = las_his.getAgreement();

            }
        }
        int changeCount = 0;
        if (deepSleep <= 120) {
            return historyHourList;
        }
        ArrayList<HistoryHour> resultHourList = new ArrayList<>();
        for (int i3 = 0; i3 < historyHourList.size(); i3++) {
            HistoryHour hour = historyHourList.get(i3);
            if (i3 == 0) {
                resultHourList.add(hour.copy());
            } else if (i3 == historyHourList.size() - 1) {
                resultHourList.add(hour.copy());
                return resultHourList;
            } else if (i3 == 1) {
                int deep_min = 0;

                HistoryHour historyHour2 = hour.copy();
                if (deep_min >= 30) {

                      resultHourList.add(historyHour2);
                } else {

                //    historyHour2.setSleepGrade(Integer.parseInt(Integer.toHexString(sleep166[0]) + Integer.toHexString(sleep166[1]) + Integer.toHexString(sleep166[2]) + Integer.toHexString(sleep166[3]), 16));
                    resultHourList.add(historyHour2);
                }
            } else {
                int[] sleep167 = null;//CalculateHelper.calculateSleepGrade(hour.getSleepGrade());
                int[] last_sleep16 = null;//CalculateHelper.calculateSleepGrade(historyHourList.get(i3 - 1).getSleepGrade());
                int fis_grade = last_sleep16[0];
                int sec_grade = last_sleep16[1];
                HistoryHour historyHour3 = hour.copy();
                if (fis_grade == 10 && sec_grade == 10) {
                    if (changeCount < 2) {
                        changeCount++;
                        if (sleep167[0] == 10) {
                            sleep167[0] = 5;
                        }
                        if (sleep167[1] == 10) {
                            sleep167[1] = 5;
                        }
                        if (sleep167[2] == 10) {
                            sleep167[2] = 5;
                        }
                        if (sleep167[3] == 10) {
                            sleep167[3] = 5;
                        }
                    } else {
                        changeCount = 0;
                        int c_hour = hour.getDate().get(11);
                        if (c_hour % 2 == 0 && c_hour < 3) {
                            if (sleep167[2] == 10) {
                                sleep167[2] = 5;
                            }
                            if (sleep167[3] == 10) {
                                sleep167[3] = 5;
                            }
                        } else if (c_hour % 2 == 0 && c_hour >= 3) {
                            if (sleep167[1] == 10) {
                                sleep167[1] = 5;
                            }
                            if (sleep167[2] == 10) {
                                sleep167[2] = 5;
                            }
                        } else if (c_hour % 2 == 0 || c_hour >= 3) {
                            if (sleep167[0] == 10) {
                                sleep167[0] = 5;
                            }
                            if (sleep167[1] == 10) {
                                sleep167[1] = 5;
                            }
                        } else {
                            if (sleep167[0] == 10) {
                                sleep167[0] = 5;
                            }
                            if (sleep167[3] == 10) {
                                sleep167[3] = 5;
                            }
                        }
                    }
                } else if (fis_grade < 10 && sec_grade == 10) {
                    changeCount = 0;
                    if (sleep167[2] == 10) {
                        sleep167[2] = 5;
                    }
                    if (sleep167[3] == 10) {
                        sleep167[3] = 5;
                    }
                } else if (fis_grade == 10 && sec_grade < 10) {
                    changeCount = 0;
                    if (sleep167[0] == 10) {
                        sleep167[0] = 5;
                    }
                    if (sleep167[1] == 10) {
                        sleep167[1] = 5;
                    }
                }
                historyHour3.setSleepGrade(Integer.parseInt(Integer.toHexString(sleep167[0]) + Integer.toHexString(sleep167[1]) + Integer.toHexString(sleep167[2]) + Integer.toHexString(sleep167[3]), 16));
                resultHourList.add(historyHour3);
            }
        }
        return resultHourList;
    }

    public static NewSleepRealData getRealNewSleepTime(Context context, Map<Calendar, NewSleepHis> map, ArrayList<NewSleepHis> list, Calendar currentDate) {
        int ii;
        ArrayList<NewSleepHis> newSleepHises = new ArrayList<>();
        boolean isBegin = false;
        boolean isFirst = false;
        boolean isEnd = false;
        int begin_position = 0;
        int end_position = 0;
        int day = currentDate.get(5);
        int startSleepPosition = -1;
        int startSleepMark = 0;
        int endSleepPosition = -1;
        int endSleepMark = 0;
        if (!(list == null || map == null)) {
            int i = 0;
            while (true) {
                if (i >= list.size()) {
                    break;
                }
                NewSleepHis sleepHis = list.get(i);
                Calendar sleepHis_datetime = sleepHis.getDate();
                String[] sleep = sleepHis.getSleeps();
                int hisDay = sleepHis.getDate().get(5);
                int hisHour = sleepHis.getDate().get(11);
                if ((hisDay < day || hisHour <= 8) && !isBegin && map.containsKey(sleepHis_datetime) && sleep != null) {
                    int ii2 = 0;
                    while (true) {
                        if (ii2 >= sleep.length) {
                            break;
                        }
                        int sleep_value = Integer.parseInt(sleep[ii2]);
                        if (sleep_value > 168 || sleep_value < 128) {
                            startSleepMark = 0;
                            startSleepPosition = -1;
                        } else {
                            if (startSleepMark == 0) {
                                startSleepPosition = i;
                                begin_position = ii2;
                            }
                            startSleepMark++;
                            if (startSleepMark == 4) {
                                isBegin = true;
                                isFirst = true;
                                break;
                            }
                        }
                        ii2++;
                    }
                }
                if (isBegin) {
                    if (isFirst) {
                        if (startSleepPosition != -1) {
                            if (startSleepPosition != i) {
                                NewSleepHis his = list.get(startSleepPosition);
                                his.setStart_minute_dif(getMinute_dif_newSleep(his.getDate()));
                                newSleepHises.add(his);
                                newSleepHises.add(sleepHis);
                            } else {
                                sleepHis.setStart_minute_dif(getMinute_dif_newSleep(sleepHis_datetime));
                                newSleepHises.add(sleepHis);
                            }
                        }
                        isFirst = false;
                    } else {
                        newSleepHises.add(sleepHis);
                    }
                }
                if (sleepHis_datetime.get(11) >= 6 && currentDate.get(5) == sleepHis_datetime.get(5) && (map.containsKey(sleepHis_datetime) && isBegin)) {
                    if (sleepHis.equals(list.get(startSleepPosition))) {
                        ii = begin_position;
                    } else {
                        ii = 0;
                    }
                    while (true) {
                        if (ii >= sleep.length) {
                            break;
                        }
                        int sleep_value2 = Integer.parseInt(sleep[ii]);
                        if (sleep_value2 < 128) {
                            endSleepPosition = i;
                            end_position = ii;
                            isEnd = true;
                            break;
                        }
                        if (sleep_value2 > 168) {
                            if (endSleepMark == 0) {
                                endSleepPosition = i;
                                end_position = ii;
                            }
                            endSleepMark++;
                            if (endSleepMark == 4) {
                                isEnd = true;
                                break;
                            }
                        } else {
                            endSleepMark = 0;
                            endSleepPosition = -1;
                        }
                        ii++;
                    }
                }
                if (!isEnd) {
                    i++;
                } else if (endSleepPosition != -1) {
                    if (endSleepPosition != i) {
                        NewSleepHis his2 = list.get(endSleepPosition);
                        his2.setEnd_minute_dif(getMinute_dif_newSleep(his2.getDate()));
                        newSleepHises.remove(sleepHis);
                    } else {
                        sleepHis.setEnd_minute_dif(getMinute_dif_newSleep(sleepHis_datetime));
                    }
                }
            }
            if (isBegin && !isEnd) {
                //   FirstSyncBean firstSyncBean = DatabaseProvider.getInstance(context).querySyncTime(FormatHelper.sdf_yyyyMMdd.format(currentDate.getTime()));

                Calendar firstCal = Calendar.getInstance();
                //  firstCal.setTime(FormatHelper.sdf_yyyyMMddHHmm.parse(firstSyncBean.toString()));
                //     int dif = Integer.parseInt(firstSyncBean.getHour_minute().substring(2, 4));
                int dif = 0;
                int count = dif / 5;
                int over = dif % 5;
                if (dif > 57) {
                    firstCal.set(11, firstCal.get(11) + 1);
                    end_position = 0;
                } else if (over < 3) {
                    end_position = count;
                } else {
                    end_position = count + 1;
                }
                Iterator<NewSleepHis> iterator = newSleepHises.iterator();
                while (iterator.hasNext()) {
                    if (iterator.next().getDate().after(firstCal)) {
                        iterator.remove();
                    }
                }
                if (newSleepHises.size() > 0) {
                    if (over < 3) {
                        //  newSleepHises.get(newSleepHises.size() - 1).setEnd_minute_dif(over);
                    } else {
                        //   newSleepHises.get(newSleepHises.size() - 1).setEnd_minute_dif(over - 5);
                    }
                }
            }
        }
        NewSleepRealData sleepRealData = new NewSleepRealData();
        sleepRealData.setBegin_position(begin_position);
        sleepRealData.setEnd_position(end_position);
        // sleepRealData.setNewSleepHises(newSleepHises);
        return sleepRealData;
    }

    public static int getMinute_dif(Calendar calendar) {
        int a = Integer.parseInt(FormatHelper.sdf_yyyyMMdd.format(calendar.getTime())) * Integer.parseInt(FormatHelper.sdf_HH.format(calendar.getTime()));
        int result = a % 8;
        if (a % 2 == 0) {
            return -result;
        }
        return result;
    }

    public static int getMinute_dif_newSleep(Calendar calendar) {
        int a = Integer.parseInt(FormatHelper.sdf_yyyyMMdd.format(calendar.getTime())) * Integer.parseInt(FormatHelper.sdf_HH.format(calendar.getTime()));
        int result = a % 3;
        if (a % 2 == 0) {
            return -result;
        }
        return result;
    }

    public static int parserSleepLevel(int totalSleepMinute, int deepMinute) {
        if (totalSleepMinute < 300 || totalSleepMinute == deepMinute) {
            return 2;
        }
        if (((double) deepMinute) >= ((double) totalSleepMinute) * 0.13d && ((double) deepMinute) <= ((double) totalSleepMinute) * 0.25d) {
            return 1;
        }
        if (((double) deepMinute) > ((double) totalSleepMinute) * 0.25d) {
            return 0;
        }
        return 2;
    }

    public static boolean isSH08Before20150928(ImgVersion imgVersion) {
        if (imgVersion != null && imgVersion.getType().equalsIgnoreCase(VersionHelper.TYPE_VERSION_SH08)) {
            Calendar cal_img = imgVersion.getDate();
            Calendar cal_20150928 = Calendar.getInstance();
            try {
                cal_20150928.setTime(FormatHelper.sdf_yyyyMMdd.parse("20150928"));
                if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20150928)) {
                    return true;
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    public static boolean isSH08orSH06Before20160501(ImgVersion imgVersion) {
        if (imgVersion != null) {
            String type = imgVersion.getType();
            if (type.equalsIgnoreCase(VersionHelper.TYPE_VERSION_SH08) || type.equalsIgnoreCase("SH06")) {
                Calendar cal_img = imgVersion.getDate();
                Calendar cal_20160501 = Calendar.getInstance();
                try {
                    cal_20160501.setTime(FormatHelper.sdf_yyyyMMdd.parse("20160501"));
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20160501)) {
                        return true;
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }

    public static boolean isNordic(ImgVersion imgVersion) {
        String version;
        if (imgVersion == null || (version = imgVersion.getVersion()) == null || version == "" || !version.contains("N")) {
            return false;
        }
        return true;
    }

    public static boolean is09ShowHeart(ImgVersion imgVersion) {
        boolean limit1;
        if (imgVersion != null && imgVersion.getType().equalsIgnoreCase("SH09")) {
            Calendar cal_img = imgVersion.getDate();
            Calendar cal_20170605 = Calendar.getInstance();
            Calendar cal_20170702 = Calendar.getInstance();
            Calendar cal_20170526 = Calendar.getInstance();
            try {
                String version = imgVersion.getVersion();
                cal_20170702.setTime(FormatHelper.sdf_yyyyMMdd.parse("20170702"));
                cal_20170605.setTime(FormatHelper.sdf_yyyyMMdd.parse("20170605"));
                cal_20170526.setTime(FormatHelper.sdf_yyyyMMdd.parse("20170526"));
                if (version.equalsIgnoreCase(Global.NORDIC_YUANXIANG)) {
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20170605) || CalendarHelper.isDate1AfterDate2(cal_img, cal_20170702)) {
                        return true;
                    }
                } else if (version.equalsIgnoreCase(Global.NORDIC_XINLV)) {
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20170526)) {
                        limit1 = true;
                    } else {
                        limit1 = false;
                    }
                    boolean limit2 = CalendarHelper.isDate1AfterDate2(cal_img, cal_20170702);
                    if (limit1 || limit2) {
                        return true;
                    }
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    public static boolean is09UShowHeart(ImgVersion imgVersion) {
        if (imgVersion != null && imgVersion.getType().equalsIgnoreCase("SH09U")) {
            Calendar cal_img = imgVersion.getDate();
            Calendar cal_20170508 = Calendar.getInstance();
            Calendar cal_20170702 = Calendar.getInstance();
            try {
                String version = imgVersion.getVersion();
                cal_20170702.setTime(FormatHelper.sdf_yyyyMMdd.parse("20170702"));
                cal_20170508.setTime(FormatHelper.sdf_yyyyMMdd.parse("20170508"));
                if (!version.equalsIgnoreCase(Global.NORDIC_XINLV) || (CalendarHelper.isDate1AfterDate2(cal_img, cal_20170508) && !CalendarHelper.isDate1AfterDate2(cal_img, cal_20170702))) {
                    return false;
                }
                return true;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    public static boolean isI8ShowHeart(ImgVersion imgVersion) {
        if (imgVersion != null && imgVersion.getType().equalsIgnoreCase("I8")) {
            Calendar cal_img = imgVersion.getDate();
            Calendar cal_20170505 = Calendar.getInstance();
            Calendar cal_20170702 = Calendar.getInstance();
            Calendar cal_20170504 = Calendar.getInstance();
            try {
                String version = imgVersion.getVersion();
                cal_20170702.setTime(FormatHelper.sdf_yyyyMMdd.parse("20170702"));
                cal_20170505.setTime(FormatHelper.sdf_yyyyMMdd.parse("20170505"));
                cal_20170504.setTime(FormatHelper.sdf_yyyyMMdd.parse("20170504"));
                if (version.equalsIgnoreCase(Global.NORDIC_YUANXIANG)) {
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20170505) || CalendarHelper.isDate1AfterDate2(cal_img, cal_20170702)) {
                        return true;
                    }
                } else if (!version.equalsIgnoreCase(Global.NORDIC_XINLV) || (CalendarHelper.isDate1AfterDate2(cal_img, cal_20170504) && !CalendarHelper.isDate1AfterDate2(cal_img, cal_20170702))) {
                    return false;
                } else {
                    return true;
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    public static boolean is09or09uNordic_YuanXiang(ImgVersion imgVersion) {
        String version;
        if (imgVersion != null) {
            String type = imgVersion.getType();
            if (type.equalsIgnoreCase("SH09") || type.equalsIgnoreCase("SH09U")) {
                Calendar cal_img = imgVersion.getDate();
                Calendar cal_20161101 = Calendar.getInstance();
                try {
                    cal_20161101.setTime(FormatHelper.sdf_yyyyMMdd.parse("20161101"));
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20161101) || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global.NORDIC_YUANXIANG)) {
                        return false;
                    }
                    return true;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }

    public static boolean is07NB(ImgVersion imgVersion) {
        String version;
        if (imgVersion == null || !imgVersion.getType().equalsIgnoreCase("SH07") || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global.NORDIC_07_NB)) {
            return false;
        }
        return true;
    }

    public static boolean is07N0(ImgVersion imgVersion) {
        String version;
        if (imgVersion == null || !imgVersion.getType().equalsIgnoreCase("SH07") || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global.NORDIC_07_N0)) {
            return false;
        }
        return true;
    }

    public static boolean isI8NX(ImgVersion imgVersion) {
        String version;
        if (imgVersion == null || !imgVersion.getType().equalsIgnoreCase("I8") || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global.NORDIC_XINLV)) {
            return false;
        }
        return true;
    }

    public static boolean is09or09uNordic_SongEn(ImgVersion imgVersion) {
        String version;
        if (imgVersion != null) {
            String type = imgVersion.getType();
            if (type.equalsIgnoreCase("SH09") || type.equalsIgnoreCase("SH09U")) {
                Calendar cal_img = imgVersion.getDate();
                Calendar cal_20161101 = Calendar.getInstance();
                try {
                    cal_20161101.setTime(FormatHelper.sdf_yyyyMMdd.parse("20161101"));
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20161101) || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global.NORDIC_SONGEN)) {
                        return false;
                    }
                    return true;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }

    public static boolean isSh09UHaveBraceletClean(ImgVersion imgVersion) {
        if (imgVersion != null && imgVersion.getType().equalsIgnoreCase("SH09U")) {
            Calendar cal_img = imgVersion.getDate();
            Calendar cal_20200226 = Calendar.getInstance();
            try {
                cal_20200226.setTime(FormatHelper.sdf_yyyyMMdd.parse("20200226"));
                if (CalendarHelper.isDate1AfterDate2(cal_img, cal_20200226)) {
                    return true;
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    public static boolean is09or09uNordic_YuCheng(ImgVersion imgVersion) {
        String version;
        if (imgVersion != null) {
            String type = imgVersion.getType();
            if (type.equalsIgnoreCase("SH09") || type.equalsIgnoreCase("SH09U")) {
                Calendar cal_img = imgVersion.getDate();
                Calendar cal_20161101 = Calendar.getInstance();
                try {
                    cal_20161101.setTime(FormatHelper.sdf_yyyyMMdd.parse("20161101"));
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20161101) || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global.NORDIC_YUCHENG)) {
                        return false;
                    }
                    return true;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }

    public static boolean is09NotHaveFont(ImgVersion imgVersion) {
        String number;
        if (imgVersion == null || !imgVersion.getType().equalsIgnoreCase("SH09") || (number = imgVersion.getNumber()) == null || number.equals("") || !number.equals("1")) {
            return false;
        }
        return true;
    }

    public static boolean is09or09uNordic_XinLv(ImgVersion imgVersion) {
        String version;
        if (imgVersion != null) {
            String type = imgVersion.getType();
            if (type.equalsIgnoreCase("SH09") || type.equalsIgnoreCase("SH09U")) {
                Calendar cal_img = imgVersion.getDate();
                Calendar cal_20161101 = Calendar.getInstance();
                try {
                    cal_20161101.setTime(FormatHelper.sdf_yyyyMMdd.parse("20161101"));
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20161101) || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global.NORDIC_XINLV)) {
                        return false;
                    }
                    return true;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }

    public static boolean is09or09uNordic_3X(ImgVersion imgVersion) {
        String version;
        if (imgVersion != null) {
            String type = imgVersion.getType();
            if (type.equalsIgnoreCase("SH09") || type.equalsIgnoreCase("SH09U")) {
                Calendar cal_img = imgVersion.getDate();
                Calendar cal_20161101 = Calendar.getInstance();
                try {
                    cal_20161101.setTime(FormatHelper.sdf_yyyyMMdd.parse("20161101"));
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20161101) || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global.NORDIC_3X)) {
                        return false;
                    }
                    return true;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }

    public static boolean is09or09u2640_AMS(ImgVersion imgVersion) {
        String version;
        if (imgVersion != null) {
            String type = imgVersion.getType();
            if (type.equalsIgnoreCase("SH09") || type.equalsIgnoreCase("SH09U")) {
                Calendar cal_img = imgVersion.getDate();
                Calendar cal_20161101 = Calendar.getInstance();
                try {
                    cal_20161101.setTime(FormatHelper.sdf_yyyyMMdd.parse("20161101"));
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20161101) || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global._2640_AMS)) {
                        return false;
                    }
                    return true;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }

    public static boolean is09or09u2640_SongEn(ImgVersion imgVersion) {
        String version;
        if (imgVersion != null) {
            String type = imgVersion.getType();
            if (type.equalsIgnoreCase("SH09") || type.equalsIgnoreCase("SH09U")) {
                Calendar cal_img = imgVersion.getDate();
                Calendar cal_20161101 = Calendar.getInstance();
                try {
                    cal_20161101.setTime(FormatHelper.sdf_yyyyMMdd.parse("20161101"));
                    if (!CalendarHelper.isDate1AfterDate2(cal_img, cal_20161101) || (version = imgVersion.getVersion()) == null || version.equals("") || !version.equalsIgnoreCase(Global._2640_SONGEN)) {
                        return false;
                    }
                    return true;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }

    public static List<HistoryHour> getCurrentDayHistoryList(Calendar currentDate, Context context, int profileID) {
        Calendar[] calArray = CalendarHelper.getSleepTime(context, profileID, currentDate);
        if (profileID != -1) {
           // return DatabaseProvider.getInstance(context).queryHistoryHour(context, profileID, calArray[0], calArray[1]);
        }
        return new ArrayList();
    }

    public static void dealNoSleepArray(NewSleepRealData sleepRealData, Calendar currentDate) {
        int max = sleepRealData.getSleep_max();
        int min = sleepRealData.getSleep_min();
        List<HistoryHour> realSleep = sleepRealData.getNewSleepHises1();
        int begin_position = sleepRealData.getBegin_position();
        int end_position = sleepRealData.getEnd_position();
        if (realSleep != null && realSleep.size() > 0) {
            List<Integer> deep_positions = getDeepPositions(currentDate, realSleep.size(), begin_position);
            for (int i = 0; i < realSleep.size(); i++) {
                String[] sleeps = realSleep.get(i).getSleeps();
                if (sleeps != null) {
                    if (i == 0) {
                        for (int start_i = begin_position; start_i < sleeps.length; start_i++) {
                            int sleep = Integer.parseInt(sleeps[start_i]);
                            if (sleep == max) {
                                sleeps[start_i] = String.valueOf((int) Global.title_receive_alarm2);
                            } else if (sleep == min) {
                                sleeps[start_i] = String.valueOf(128);
                            } else if (sleep < max && sleep > min && sleep > 128) {
                                sleeps[start_i] = String.valueOf((int) Global.title_receive_language);
                            }
                            Iterator<Integer> it = deep_positions.iterator();
                            while (true) {
                                if (!it.hasNext()) {
                                    break;
                                }
                                Integer deep = it.next();
                                if (deep.intValue() == start_i && sleep >= 128) {
                                    sleeps[start_i] = String.valueOf(128);
                                    deep_positions.remove(deep);
                                    break;
                                }
                            }
                        }
                    } else if (i == realSleep.size() - 1) {
                        for (int end_i = 0; end_i <= end_position; end_i++) {
                            int sleep2 = Integer.parseInt(sleeps[end_i]);
                            if (sleep2 == max) {
                                sleeps[end_i] = String.valueOf((int) Global.title_receive_alarm2);
                            } else if (sleep2 == min) {
                                sleeps[end_i] = String.valueOf(128);
                            } else if (sleep2 < max && sleep2 > min && sleep2 > 128) {
                                sleeps[end_i] = String.valueOf((int) Global.title_receive_language);
                            }
                        }
                    } else {
                        for (int center_i = 0; center_i < sleeps.length; center_i++) {
                            int sleep3 = Integer.parseInt(sleeps[center_i]);
                            if (sleep3 == max) {
                                sleeps[center_i] = String.valueOf((int) Global.title_receive_alarm2);
                            } else if (sleep3 == min) {
                                sleeps[center_i] = String.valueOf(128);
                            } else if (sleep3 < max && sleep3 > min && sleep3 > 128) {
                                sleeps[center_i] = String.valueOf((int) Global.title_receive_language);
                            }
                            int nowPosition = ((i - 1) * 12) + (12 - begin_position) + center_i;
                            Iterator<Integer> it2 = deep_positions.iterator();
                            while (true) {
                                if (!it2.hasNext()) {
                                    break;
                                }
                                Integer deep2 = it2.next();
                                if (deep2.intValue() == nowPosition && sleep3 >= 128) {
                                    sleeps[center_i] = String.valueOf(128);
                                    deep_positions.remove(deep2);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    private static List<Integer> getDeepPositions(Calendar currentDay, int hour_num, int begin_position) {
        List<Integer> deep_positions = new LinkedList<>();
        int day = currentDay.get(5);
        int m = ((hour_num - 2) * 12) + (12 - begin_position);
        int num = ((hour_num - 8) * 3) + 16;
        if (num > 16) {
            num = 16;
        } else if (num < 0) {
            num = 0;
        }
        int[] position = new int[(num + 1)];
        position[0] = (day * 100) + 1;
        for (int i = 1; i < num + 1; i++) {
            int value = ((position[i - 1] * 1111) + 7) % m;
            position[i] = value;
            deep_positions.add(Integer.valueOf(value));
        }
        return deep_positions;
    }
}
